// 作业提交路由
const express = require('express');
const router = express.Router();
const multer = require('multer');
const SubmissionController = require('../controllers/submissionController');
const { authMiddleware, teacherMiddleware, studentMiddleware } = require('../utils/authMiddleware');
const { singleFileUpload } = require('../utils/uploadConfig');

// 配置multer处理multipart/form-data，但不保存文件，仅用于解析表单字段
// 设置更大的请求体大小限制，支持较大的图片上传
const formDataParser = multer({
  limits: {
    fieldSize: 50 * 1024 * 1024 // 50MB
  }
});

/**
 * 作业提交路由
 * 定义作业提交和评分相关的API端点
 */

// 学生提交作业 - 使用multer的none()中间件仅解析表单字段，不要求文件上传
router.post('/', authMiddleware, studentMiddleware, formDataParser.none(), SubmissionController.submitHomework);

// 学生查看自己的提交历史
router.get('/student', authMiddleware, studentMiddleware, SubmissionController.getStudentSubmissions);

// 教师专用路由
router.get('/', authMiddleware, teacherMiddleware, SubmissionController.getSubmissionList);
router.put('/:submissionId/grade', authMiddleware, teacherMiddleware, SubmissionController.gradeSubmission);
router.put('/:submissionId/reject', authMiddleware, teacherMiddleware, SubmissionController.rejectSubmission);

// 排名相关路由（学生和教师都可以查看）
router.get('/rankings/grade', authMiddleware, SubmissionController.getGradeRanking);
router.get('/rankings/class/:classId', authMiddleware, SubmissionController.getClassRanking);

module.exports = router;